import { useIntersectionObserver } from "@vueuse/core";

//定义懒加载插件
export const lazyPlugin = {
    install(app) {
        //懒加载逻辑
        app.directive('img-lazy', {
            mounted(el, binding) {
                //el 指令绑定的元素
                //binding 绑定对象 图片url
                console.log(el, binding.value);
                const { stop } = useIntersectionObserver(
                    el,
                    ([isIntersecting]) => {
                        console.log(isIntersecting);
                        if (isIntersecting) {
                            //进入入口区域
                            el.src = binding.value
                            stop();
                        }


                    },
                )

            }
        })
    }
}
